/*
 * key_app.c
 *
 *  Created on: Jul 20, 2022
 *      Author: fanlida
 */
#include "key_middle.h"
#include <stdio.h>
#include "fifo.h"

/*************************************模拟按键IO函数-START*****************************************/
//#include "gpio.h"
//以下为模拟按键，按键IO函数根据单片机IO状态进行修改
unsigned char KeyStatus;
static unsigned char IsKey1Down(void)
{
	return(KeyStatus);
}

static unsigned char IsKey2Down(void)
{
	return(KeyStatus);
}
/*********************************模拟按键IO函数-END***********************************************/


/*********************************KEY&FIFO关联实现函数-START***************************************/
/*key fifo*/
#define 				LISTSIZE		50					//Key Fifo 缓冲区大小
static fifo_t 			fifo_key;							//定义key_fifo结构体
static unsigned char	ListKey[LISTSIZE];					//定义Key Fifo 缓冲区

/*key初始化*/
static char FifoInitKey(void)
{
	return (fifo_init(&fifo_key, ListKey, LISTSIZE));
}
/*key fifo 元素数量获取*/
static unsigned int FifoLenKey(void)
{
	return(fifo_len(&fifo_key));
}
/*fifo中存放key信息*/
static unsigned int FifoPutKey(unsigned char *buf, unsigned int len)
{
	return(fifo_put(&fifo_key, buf, len));
}
/*从fifo中获取key信息*/
static unsigned int FifoGetKey(unsigned char *buf, unsigned int len)
{
	return(fifo_get(&fifo_key, buf, len));
}

/************************************KEY&FIFO关联实现函数-END***************************************/

//按键初始化
void KeyInit(void)
{
	//按键的FIFO初始化
	FifoInitKey();
	//将三个FIFO相关函数指针进行注册
	FifoFuncRegister(FifoLenKey, FifoPutKey, FifoGetKey);
	//配置KEY_1,打开长按监测，打开长按输出，IO状态函数
	KeyAdd(KEY_1, ENABLE, ENABLE, IsKey1Down);
//	KeyAdd(KEY_2, ENABLE, ENABLE, IsKey2Down);
}

//10ms调用
void KeyHandle(void)
{
	struct KEY_T *pKey = NULL;
	
	pKey = KeyList;
	
	while(pKey != NULL)
	{
		KeyCheck(pKey);
		pKey = pKey->next;
	}
}

char KeyInfoOutput(KeyInfo_t *KeyInfo)
{

	return(GetKeyInfo(KeyInfo));
}




